/*
* This file is part of RoboDS (http://code.google.com/p/robods/)
* Copyright (C) 2007 Blakharaz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

#include "DsMap.h"

#include "DsEmptyTile.h"
#include "DsPitTile.h"
#include "SpriteManager.h"
#include "DsWallTile.h"

namespace robo
{

    DsMap::DsMap(unsigned int length, unsigned int height)
     : Map(length, height),
     mZoom(ZOOM_NORMAL), mScrollOffset(0, 0)
    {
    }

    DsMap::~DsMap()
    {
    }

    void DsMap::update()
    {
        for (MapMap::const_iterator it
            = mMapTiles.begin(); it != mMapTiles.end(); ++it)
        {
            it->second->update();
        }
        
        s32 zoomVal = 256;

        switch (mZoom)
        {
        case ZOOM_HALF:
            zoomVal = 128;
            break;
        case ZOOM_NORMAL:
            zoomVal = 256;
            break;
        case ZOOM_DOUBLE:
            zoomVal = 512;
            break;
        }
        
        PA_SetBgRot(1, SpriteManager::BACKGROUND_MAP, mScrollOffset.X, mScrollOffset.Y, 0, 0, 0, zoomVal);
    }

    AbstractTile* DsMap::createTile(
        const char& type, unsigned short x, unsigned short y) const
    {
        switch (type)
        {
        case ' ':
            return new DsEmptyTile(x, y);
        case 'b':
		    return new DsWallTile(x, y, BOTTOM);
        case 't':
            return new DsWallTile(x, y, TOP);
        case 'r':
            return new DsWallTile(x, y, RIGHT);
        case 'l':
            return new DsWallTile(x, y, LEFT);
        case 'O':
            return new DsPitTile(x, y);
        }

        return NULL;
    }

    void DsMap::setZoom(Zoom zoom)
    {
        mZoom = zoom;
        update();
    }

}
